using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVGHEAD
    {
        public DataRow Convert2VGHEAD(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVGHEAD(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VGHMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VGHAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["VGHAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["VGHAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["VGHAENZL"] = " ".PadRight(0 ); 
         dwReturn["VGHAENB"] = " ".PadRight(8 ); 
         dwReturn["VGHAEND"] = " ".PadRight(0 ); 
         dwReturn["VGHNEUB"] = " ".PadRight(8 ); 
         dwReturn["VGHNEUD"] = " ".PadRight(0 ); 
         dwReturn["VGHERL"] = " ".PadRight(1 ); 
         dwReturn["VGHKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["VGHMENGE"] = " ".PadRight(0 ); 
         dwReturn["VGHVB"] = " ".PadRight(3 ); 
         dwReturn["VGHVG"] = " ".PadRight(3 ); 
         dwReturn["VGHSACHB"] = " ".PadRight(8 ); 
         dwReturn["VGHADRSL"] = " ".PadRight(8 ); 
         dwReturn["VGHKOLL"] = " ".PadRight(5 ); 
         dwReturn["VGHART"] = " ".PadRight(24 ); 
         dwReturn["VGHFARBE"] = " ".PadRight(10 ); 
         dwReturn["VGHARTST"] = " ".PadRight(1 ); 
         dwReturn["VGHPARTIE"] = " ".PadRight(11 ); 
         dwReturn["VGHGPARTIE"] = " ".PadRight(11 ); 
         dwReturn["VGHPAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["VGHPAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["VGHPAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["VGHMELD"] = " ".PadRight(1 ); 
         dwReturn["VGHPPAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["VGHPPAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["VGHPPAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["VGHTP"] = " ".PadRight(4 ); 
         dwReturn["VGHSTKNR"] = " ".PadRight(12 ); 
         dwReturn["VGHWVDAT"] = " ".PadRight(0 ); 
         dwReturn["VGHBEMETIK"] = " ".PadRight(30 ); 
         dwReturn["VGHLIEFNR"] = " ".PadRight(8 ); 
         dwReturn["VGHGESSTA"] = " ".PadRight(1 ); 
         dwReturn["VGHFRWICK"] = " ".PadRight(1 ); 
         dwReturn["VGHVERSDAT"] = " ".PadRight(0 ); 
         dwReturn["VGHREAKDAT"] = " ".PadRight(0 ); 
         dwReturn["VGHDSACHB"] = " ".PadRight(8 ); 
         dwReturn["VGHVTLNR"] = " ".PadRight(4 ); 
         dwReturn["VGHVERSLO"] = " ".PadRight(2 ); 
         dwReturn["VGHEINZSTA1"] = " ".PadRight(1 ); 
         dwReturn["VGHTVERSDAT1"] = " ".PadRight(0 ); 
         dwReturn["VGHTREAKDAT1"] = " ".PadRight(0 ); 
         dwReturn["VGHTBEM1"] = " ".PadRight(40 ); 
         dwReturn["VGHEINZSTA2"] = " ".PadRight(1 ); 
         dwReturn["VGHTVERSDAT2"] = " ".PadRight(0 ); 
         dwReturn["VGHTREAKDAT2"] = " ".PadRight(0 ); 
         dwReturn["VGHTBEM2"] = " ".PadRight(40 ); 
         dwReturn["VGHEINZSTA3"] = " ".PadRight(1 ); 
         dwReturn["VGHTVERSDAT3"] = " ".PadRight(0 ); 
         dwReturn["VGHTREAKDAT3"] = " ".PadRight(0 ); 
         dwReturn["VGHTBEM3"] = " ".PadRight(40 ); 
         dwReturn["VGHEINZSTA4"] = " ".PadRight(1 ); 
         dwReturn["VGHTVERSDAT4"] = " ".PadRight(0 ); 
         dwReturn["VGHTREAKDAT4"] = " ".PadRight(0 ); 
         dwReturn["VGHTBEM4"] = " ".PadRight(40 ); 
         dwReturn["VGHWARSCH"] = " ".PadRight(54 ); 
         dwReturn["VGHINTERN"] = " ".PadRight(60 ); 
         dwReturn["VGHFILLER"] = " ".PadRight(99 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVGHEAD(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVGHEAD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVGHEAD(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVGHEAD(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVGHEAD(dwLocal, ITXDBVERSION);
            }
            UpdateVGHEAD(dwLocal);
        }
        public void InsertVGHEAD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VGHEAD(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVGHEAD(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VGHEAD WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VGHEAD  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VGHEAD";
            Return = Result;
            return Return;
        }
        public void DeleteVGHEAD(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VGHEAD   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVGHEAD(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VGHEAD SET "
                    +"VGHMANDANT= :VGHMANDANT,"
                    +"VGHAUFKRS= :VGHAUFKRS,"
                    +"VGHAUFLFD= :VGHAUFLFD,"
                    +"VGHAUFPOS= :VGHAUFPOS,"
                    +"VGHAENZL= :VGHAENZL,"
                    +"VGHAENB= :VGHAENB,"
                    +"VGHAEND= :VGHAEND,"
                    +"VGHNEUB= :VGHNEUB,"
                    +"VGHNEUD= :VGHNEUD,"
                    +"VGHERL= :VGHERL,"
                    +"VGHKUNDNR= :VGHKUNDNR,"
                    +"VGHMENGE= :VGHMENGE,"
                    +"VGHVB= :VGHVB,"
                    +"VGHVG= :VGHVG,"
                    +"VGHSACHB= :VGHSACHB,"
                    +"VGHADRSL= :VGHADRSL,"
                    +"VGHKOLL= :VGHKOLL,"
                    +"VGHART= :VGHART,"
                    +"VGHFARBE= :VGHFARBE,"
                    +"VGHARTST= :VGHARTST,"
                    +"VGHPARTIE= :VGHPARTIE,"
                    +"VGHGPARTIE= :VGHGPARTIE,"
                    +"VGHPAUFKRS= :VGHPAUFKRS,"
                    +"VGHPAUFLFD= :VGHPAUFLFD,"
                    +"VGHPAUFPOS= :VGHPAUFPOS,"
                    +"VGHMELD= :VGHMELD,"
                    +"VGHPPAUFKRS= :VGHPPAUFKRS,"
                    +"VGHPPAUFLFD= :VGHPPAUFLFD,"
                    +"VGHPPAUFPOS= :VGHPPAUFPOS,"
                    +"VGHTP= :VGHTP,"
                    +"VGHSTKNR= :VGHSTKNR,"
                    +"VGHWVDAT= :VGHWVDAT,"
                    +"VGHBEMETIK= :VGHBEMETIK,"
                    +"VGHLIEFNR= :VGHLIEFNR,"
                    +"VGHGESSTA= :VGHGESSTA,"
                    +"VGHFRWICK= :VGHFRWICK,"
                    +"VGHVERSDAT= :VGHVERSDAT,"
                    +"VGHREAKDAT= :VGHREAKDAT,"
                    +"VGHDSACHB= :VGHDSACHB,"
                    +"VGHVTLNR= :VGHVTLNR,"
                    +"VGHVERSLO= :VGHVERSLO,"
                    +"VGHEINZSTA1= :VGHEINZSTA1,"
                    +"VGHTVERSDAT1= :VGHTVERSDAT1,"
                    +"VGHTREAKDAT1= :VGHTREAKDAT1,"
                    +"VGHTBEM1= :VGHTBEM1,"
                    +"VGHEINZSTA2= :VGHEINZSTA2,"
                    +"VGHTVERSDAT2= :VGHTVERSDAT2,"
                    +"VGHTREAKDAT2= :VGHTREAKDAT2,"
                    +"VGHTBEM2= :VGHTBEM2,"
                    +"VGHEINZSTA3= :VGHEINZSTA3,"
                    +"VGHTVERSDAT3= :VGHTVERSDAT3,"
                    +"VGHTREAKDAT3= :VGHTREAKDAT3,"
                    +"VGHTBEM3= :VGHTBEM3,"
                    +"VGHEINZSTA4= :VGHEINZSTA4,"
                    +"VGHTVERSDAT4= :VGHTVERSDAT4,"
                    +"VGHTREAKDAT4= :VGHTREAKDAT4,"
                    +"VGHTBEM4= :VGHTBEM4,"
                    +"VGHWARSCH= :VGHWARSCH,"
                    +"VGHINTERN= :VGHINTERN,"
                    +"VGHFILLER= :VGHFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VGHMANDANT", OracleType.NVarChar).Value = dwData["VGHMANDANT"].ToString(); 
          or1.Parameters.Add("VGHAUFKRS", OracleType.NVarChar).Value = dwData["VGHAUFKRS"].ToString(); 
          or1.Parameters.Add("VGHAUFLFD", OracleType.NVarChar).Value = dwData["VGHAUFLFD"].ToString(); 
          or1.Parameters.Add("VGHAUFPOS", OracleType.NVarChar).Value = dwData["VGHAUFPOS"].ToString(); 
          or1.Parameters.Add("VGHAENZL", OracleType.NVarChar).Value = dwData["VGHAENZL"].ToString(); 
          or1.Parameters.Add("VGHAENB", OracleType.NVarChar).Value = dwData["VGHAENB"].ToString(); 
          or1.Parameters.Add("VGHAEND", OracleType.NVarChar).Value = dwData["VGHAEND"].ToString(); 
          or1.Parameters.Add("VGHNEUB", OracleType.NVarChar).Value = dwData["VGHNEUB"].ToString(); 
          or1.Parameters.Add("VGHNEUD", OracleType.NVarChar).Value = dwData["VGHNEUD"].ToString(); 
          or1.Parameters.Add("VGHERL", OracleType.NVarChar).Value = dwData["VGHERL"].ToString(); 
          or1.Parameters.Add("VGHKUNDNR", OracleType.NVarChar).Value = dwData["VGHKUNDNR"].ToString(); 
          or1.Parameters.Add("VGHMENGE", OracleType.NVarChar).Value = dwData["VGHMENGE"].ToString(); 
          or1.Parameters.Add("VGHVB", OracleType.NVarChar).Value = dwData["VGHVB"].ToString(); 
          or1.Parameters.Add("VGHVG", OracleType.NVarChar).Value = dwData["VGHVG"].ToString(); 
          or1.Parameters.Add("VGHSACHB", OracleType.NVarChar).Value = dwData["VGHSACHB"].ToString(); 
          or1.Parameters.Add("VGHADRSL", OracleType.NVarChar).Value = dwData["VGHADRSL"].ToString(); 
          or1.Parameters.Add("VGHKOLL", OracleType.NVarChar).Value = dwData["VGHKOLL"].ToString(); 
          or1.Parameters.Add("VGHART", OracleType.NVarChar).Value = dwData["VGHART"].ToString(); 
          or1.Parameters.Add("VGHFARBE", OracleType.NVarChar).Value = dwData["VGHFARBE"].ToString(); 
          or1.Parameters.Add("VGHARTST", OracleType.NVarChar).Value = dwData["VGHARTST"].ToString(); 
          or1.Parameters.Add("VGHPARTIE", OracleType.NVarChar).Value = dwData["VGHPARTIE"].ToString(); 
          or1.Parameters.Add("VGHGPARTIE", OracleType.NVarChar).Value = dwData["VGHGPARTIE"].ToString(); 
          or1.Parameters.Add("VGHPAUFKRS", OracleType.NVarChar).Value = dwData["VGHPAUFKRS"].ToString(); 
          or1.Parameters.Add("VGHPAUFLFD", OracleType.NVarChar).Value = dwData["VGHPAUFLFD"].ToString(); 
          or1.Parameters.Add("VGHPAUFPOS", OracleType.NVarChar).Value = dwData["VGHPAUFPOS"].ToString(); 
          or1.Parameters.Add("VGHMELD", OracleType.NVarChar).Value = dwData["VGHMELD"].ToString(); 
          or1.Parameters.Add("VGHPPAUFKRS", OracleType.NVarChar).Value = dwData["VGHPPAUFKRS"].ToString(); 
          or1.Parameters.Add("VGHPPAUFLFD", OracleType.NVarChar).Value = dwData["VGHPPAUFLFD"].ToString(); 
          or1.Parameters.Add("VGHPPAUFPOS", OracleType.NVarChar).Value = dwData["VGHPPAUFPOS"].ToString(); 
          or1.Parameters.Add("VGHTP", OracleType.NVarChar).Value = dwData["VGHTP"].ToString(); 
          or1.Parameters.Add("VGHSTKNR", OracleType.NVarChar).Value = dwData["VGHSTKNR"].ToString(); 
          or1.Parameters.Add("VGHWVDAT", OracleType.NVarChar).Value = dwData["VGHWVDAT"].ToString(); 
          or1.Parameters.Add("VGHBEMETIK", OracleType.NVarChar).Value = dwData["VGHBEMETIK"].ToString(); 
          or1.Parameters.Add("VGHLIEFNR", OracleType.NVarChar).Value = dwData["VGHLIEFNR"].ToString(); 
          or1.Parameters.Add("VGHGESSTA", OracleType.NVarChar).Value = dwData["VGHGESSTA"].ToString(); 
          or1.Parameters.Add("VGHFRWICK", OracleType.NVarChar).Value = dwData["VGHFRWICK"].ToString(); 
          or1.Parameters.Add("VGHVERSDAT", OracleType.NVarChar).Value = dwData["VGHVERSDAT"].ToString(); 
          or1.Parameters.Add("VGHREAKDAT", OracleType.NVarChar).Value = dwData["VGHREAKDAT"].ToString(); 
          or1.Parameters.Add("VGHDSACHB", OracleType.NVarChar).Value = dwData["VGHDSACHB"].ToString(); 
          or1.Parameters.Add("VGHVTLNR", OracleType.NVarChar).Value = dwData["VGHVTLNR"].ToString(); 
          or1.Parameters.Add("VGHVERSLO", OracleType.NVarChar).Value = dwData["VGHVERSLO"].ToString(); 
          or1.Parameters.Add("VGHEINZSTA1", OracleType.NVarChar).Value = dwData["VGHEINZSTA1"].ToString(); 
          or1.Parameters.Add("VGHTVERSDAT1", OracleType.NVarChar).Value = dwData["VGHTVERSDAT1"].ToString(); 
          or1.Parameters.Add("VGHTREAKDAT1", OracleType.NVarChar).Value = dwData["VGHTREAKDAT1"].ToString(); 
          or1.Parameters.Add("VGHTBEM1", OracleType.NVarChar).Value = dwData["VGHTBEM1"].ToString(); 
          or1.Parameters.Add("VGHEINZSTA2", OracleType.NVarChar).Value = dwData["VGHEINZSTA2"].ToString(); 
          or1.Parameters.Add("VGHTVERSDAT2", OracleType.NVarChar).Value = dwData["VGHTVERSDAT2"].ToString(); 
          or1.Parameters.Add("VGHTREAKDAT2", OracleType.NVarChar).Value = dwData["VGHTREAKDAT2"].ToString(); 
          or1.Parameters.Add("VGHTBEM2", OracleType.NVarChar).Value = dwData["VGHTBEM2"].ToString(); 
          or1.Parameters.Add("VGHEINZSTA3", OracleType.NVarChar).Value = dwData["VGHEINZSTA3"].ToString(); 
          or1.Parameters.Add("VGHTVERSDAT3", OracleType.NVarChar).Value = dwData["VGHTVERSDAT3"].ToString(); 
          or1.Parameters.Add("VGHTREAKDAT3", OracleType.NVarChar).Value = dwData["VGHTREAKDAT3"].ToString(); 
          or1.Parameters.Add("VGHTBEM3", OracleType.NVarChar).Value = dwData["VGHTBEM3"].ToString(); 
          or1.Parameters.Add("VGHEINZSTA4", OracleType.NVarChar).Value = dwData["VGHEINZSTA4"].ToString(); 
          or1.Parameters.Add("VGHTVERSDAT4", OracleType.NVarChar).Value = dwData["VGHTVERSDAT4"].ToString(); 
          or1.Parameters.Add("VGHTREAKDAT4", OracleType.NVarChar).Value = dwData["VGHTREAKDAT4"].ToString(); 
          or1.Parameters.Add("VGHTBEM4", OracleType.NVarChar).Value = dwData["VGHTBEM4"].ToString(); 
          or1.Parameters.Add("VGHWARSCH", OracleType.NVarChar).Value = dwData["VGHWARSCH"].ToString(); 
          or1.Parameters.Add("VGHINTERN", OracleType.NVarChar).Value = dwData["VGHINTERN"].ToString(); 
          or1.Parameters.Add("VGHFILLER", OracleType.NVarChar).Value = dwData["VGHFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
